package com.zhongketech.sunflower.database;

import com.zhongketech.sunflower.util.Constants;
import com.zhongketech.sunflower.util.Utilities;

import android.content.ContentValues;
import android.graphics.Bitmap;

/**
 * 应用相关的信息
 * @author 905904
 *
 */
public class ApplicationData {

	private final static String TAG = "ApplicationData";
	private final static String packageNameKey = "packageName";
	private final static String appNameKey = "appName";
	ContentValues cv = new ContentValues();

	public ApplicationData(String packageName, String appName)
	{
		if(null == packageName && null == appName)
		{
			return ;
		}

		cv.put(packageNameKey, packageName);
		cv.put(appNameKey, appName);
	}

	public String getPackageName()
	{
		return cv.getAsString(packageNameKey);
	}

	public String getAppName()
	{
		return cv.getAsString(appNameKey);
	}

	public ContentValues getContentValues()
	{
		return cv;
	}

	/**
	 * 
	 * @param ori
	 * @param des
	 * @return 
	 */
	public int getStatus(ApplicationData app)
	{
		//包名不为空且包名不相同，添加。包名不为空，包名相等，存在！包名相等，但是应用名字相同，不做任何处理
		if(null != app.getPackageName() && null != this.getPackageName() )
		{
			if(app.getPackageName().equals(this.getPackageName()))
			{

				if(null != this.getAppName())
				{
					return Constants.ITEM_UPDATE;
				}
				else
				{
					Utilities.logCat(TAG, "app package is same", Constants.LOG_INFO);
					return Constants.ITEM_EXISTS;
				}

			}
			else
			{
				return Constants.ITEM_ADD;
			}
		}
		else if(null != app.getAppName() && null != this.getAppName())
		{
			if(app.getAppName().equals(this.getAppName()))
			{
				Utilities.logCat(TAG, "no packageName and appName is Same", Constants.LOG_INFO);
				return Constants.ITEM_EXISTS;
			}
			else
			{
				return Constants.ITEM_ADD;
			}
		}

		return Constants.ITEM_ADD;
	}
}
